{extend name="base" /}
{block name="content"}
<!--tab标签-->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">权限组</li>
                <li class=""><a href="{:url('admin/auth_group/add')}">添加权限组</a></li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <form class="layui-form" action="">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th style="width: 30px;">ID</th>
                                <th>名称</th>
                                <th>状态</th>
                                <th style="width: 120px;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach name="auth_group_list" item="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.title}</td>
                                <td><input type="checkbox" name="status" lay-skin="switch" lay-filter="switchTest" value="{$vo.id}" lay-text="启用|禁用" {if condition="$vo.status==1"}checked{/if}></td>
                                <td>
                                    <div class="layui-btn-group">
                                        <a href="{:url('admin/auth_group/auth',['id'=>$vo['id']])}" class="layui-btn layui-btn-sm" title="授权"><i class="layui-icon">&#xe620;</i></a>
                                        <a href="{:url('admin/auth_group/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-sm" title="编辑"><i class="layui-icon">&#xe642;</i></a>
                                        <a href="{:url('admin/auth_group/delete',['id'=>$vo['id']])}" class="layui-btn layui-btn-sm ajax-delete" title="删除"><i class="layui-icon">&#xe640;</i></a>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    layui.use(['layer','form'], function(){ //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
        var form = layui.form;

        /**
         * 通用删除
         */
        $('.ajax-delete').on('click', function () {
            var _href = $(this).attr('href');
            layer.open({
                shade: false,
                content: '确定删除？',
                btn: ['确定', '取消'],
                yes: function (index) {
                    $.ajax({
                        url: _href,
                        type: "get",
                        success: function (info) {
                            if (info.code === 1) {
                                setTimeout(function () {
                                    location.href = info.url;
                                }, 1000);
                            }
                            layer.msg(info.msg);
                        }
                    });
                    layer.close(index);
                }
            });

            return false;
        });


        //监听指定开关
        form.on('switch(switchTest)', function(data){
            if(this.checked==true){
                var status=1;
            }else{
                var status=0;
            }
            $.ajax({
                url: "{:url('admin/auth_group/update')}?id="+this.value+"&status="+status,
                type: "get",
                success: function (info) {
                    setTimeout(function () {
                        location.href = info.url;
                    }, 1000);
                    layer.msg(info.msg);
                }
            });
            return false;
        });

    });
</script>
{/block}